package components;

import bluetooth.BlueCanvasBuilder;
import bluetooth.BlueUtil;
import components.CtrlPcCanvas;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;

import midlet.ClientApp;

/**
 * 
 * @author cccssw
 * 
 */
public class IntroCanvas extends Canvas implements CommandListener {
    //按钮控件

    private Command cmdExit = null;
    private Command cmdContinue = null;
    final String[] strHelp = {
        "Press continue"
    };

    public IntroCanvas() {
        this.setTitle("introduction");

        initCanvas();
    }

    private void initCanvas() {
        //添加退出按钮
        cmdExit = new Command("Exit", Command.EXIT, 1);
        this.addCommand(cmdExit);

        //添加继续按钮
        cmdContinue = new Command("Continue", Command.SCREEN, 1);
        this.addCommand(cmdContinue);

        this.setCommandListener(this);
    }

    public void commandAction(Command cmd, Displayable dis) {
        if (cmd == cmdExit) {
            ClientApp.exitMidlet();
        } else if (cmd == cmdContinue) {
            
            BlueCanvasBuilder bcc=new BlueCanvasBuilder(new CtrlPcCanvas(),ClientApp.instance);
            
            new Thread(bcc).start();
        }
    }

    protected void paint(Graphics g) {
        // 清空画布
        g.setColor(255, 255, 100);
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
        g.setColor(0, 0, 0);

        //在画布界面填写操作提示信息
        Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
        g.setFont(font);

        for (int i = 0; i < strHelp.length; i++) {
            g.drawString(strHelp[i], 10, 5 + 20 * i, Graphics.TOP | Graphics.LEFT);
        }
    }
}
